//
//  HYThemeViewModel.m
//  _normal
//
//  Created by Ezra on 16/6/6.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "HYThemeViewModel.h"
#import "HYThemeItem.h"
#import "HYCommentItem.h"

@implementation HYThemeViewModel

-(void)setItem:(HYThemeItem *)item
{
    _item = item;
    
    //计算顶部view的frame
    CGFloat textY = 70;
    CGFloat margin = 10;
    CGFloat textW = HYScreenW - margin *2;
//  CGFloat textH = [item.text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
    
    
//  NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};

//  CGFloat textH = [item.text boundingRectWithSize:CGSizeMake(textW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size.height;
    
    CGFloat textH = 0;

    CGFloat topViewX = 0;
    CGFloat topViewY = 0;
    CGFloat topViewW = HYScreenW;
    CGFloat topViewH = textY + textH;
    
    self.topViewFrame = CGRectMake(topViewX, topViewY, topViewW, topViewH);

//    self.cellH = topViewH + margin;
    

    
    
    //中间的View
    //判断不是文本View就计算中间View
//    if (item.filetype != HYThemeTypeText) {

        CGFloat midViewX = margin;
        CGFloat midViewY = topViewH + margin;
        CGFloat midViewW = textW;
//        CGFloat midViewH = textW / item.width * item.height;//注意！！！

        CGFloat midViewH  = 130;

        if (midViewH > HYScreenH) {
            midViewH = 300;
            item.is_big = YES;
        }

        self.middleViewFrame = CGRectMake(midViewX, midViewY, midViewW, midViewH);

        self.cellH = CGRectGetMaxY(self.middleViewFrame) + margin;
    
//    }
    
    
    //热门评论View
    if (item.commentItem) {
        
        CGFloat hotViewH = 41;
        
        if (item.commentItem.content.length) {
            textH = [item.commentItem.allContent sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
            
            hotViewH = textH + margin * 2;
        }
        
        CGFloat hotViewX = margin;
        CGFloat hotViewY = _cellH;
        CGFloat hotViewW = textW;
        self.hotViewFrame = CGRectMake(hotViewX, hotViewY, hotViewW, hotViewH);
        
        _cellH = CGRectGetMaxY(_hotViewFrame) + margin;
    }
    
//    CGFloat bottomViewX = 0;
//    CGFloat bottomViewY = _cellH;
//    CGFloat bottomViewW = HYScreenW;
//    CGFloat bottomViewH = 35;
    
    
    CGFloat bottomViewX = 0;
    CGFloat bottomViewY = 220;
    CGFloat bottomViewW = HYScreenW;
    CGFloat bottomViewH = 35;
    
    self.bottomViewFrame = CGRectMake(bottomViewX, bottomViewY, bottomViewW, bottomViewH);
    
    //加一个间距为了，调整cell之前露出的内容合适
    _cellH = CGRectGetMaxY(self.bottomViewFrame) + margin;
    
}

@end
